package com.csxy.nyf.controller;

import com.csxy.nyf.R;
import com.csxy.nyf.entity.vo.OneSubject;
import com.csxy.nyf.service.EduSubjectService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {
    @Autowired
    private EduSubjectService eduSubjectService;

    //课程分类列表（树形）
    @Operation(description = "嵌套数据列表")
    @GetMapping("/getAllSubject")
    public R getAllSubject() {
        //list 集合泛型是一级分类，一级分类里面有多个二级分类
        List<OneSubject> list = eduSubjectService.getAllOneTwoSubject();
        return R.ok().data("list", list);
    }

    //添加课程分类
    //获取上传过来的 文件，把文件内容读取出来
    @PostMapping("/addSubject")
    public R addSubject(MultipartFile file) {
        //获取上传的excel文件 MultipartFile


        eduSubjectService.saveSubject(file, eduSubjectService);
        //判断返回集合是否为空

        return R.ok();
    }


}
